<!DOCTYPE html>
<html>
<head>
	<title>E8NET</title>
    
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <include file="./App/Admin/View/Include/css.html" />
    <!-- this page specific styles -->
    <link rel="stylesheet" href="__PUBLIC__/Libs/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" media="screen" />
    <!-- this page specific styles -->
    <link rel="stylesheet" href="__PUBLIC__/Admin/css/compiled/personal-info.css" type="text/css" media="screen" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

    <include file="./App/Admin/View/Include/navbar.html" />
    <include file="./App/Admin/View/Include/menu.html" />

    <div class="content">

        <div role="breadcrumb">
            <ol class="breadcrumb">
              <li><a href="#">App设置</a> / </li>
              <li><a href="{:U('Version/index')}">版本控制</a> / </li>
              <li class="active">添加新版本</li>
            </ol>
        </div>

        <div class="container-fluid">
            <div class="settings-wrapper" id="pad-wrapper">
                <!-- avatar column -->
                <div class="span2 avatar-box">
                    <div class="personal-image" style="text-align: center;">
                        <img src="__PUBLIC__/Admin/img/apk.png" class="" />
                        <p>添加Apk文件</p>
                        
                        <div class="">
                            <div id="filelist">请选择一个文件.</div>
                            <div id="container">
                                <a id="pickfiles" href="javascript:;">[选择文件]</a>
                                <a id="uploadfiles" href="javascript:;">[上传文件]</a>
                            </div>
                        </div>

                    </div>
                </div>

                <!-- edit form column -->
                <div class="span7 personal-info">
                    <h5 class="personal-title">发布新版本</h5>

                    <form id="version-form" />

                        <input type="hidden" name="download_url" id="apk" />
                        <div class="field-box">
                            <label>版本号:</label>
                            <input class="span5 inline-input" name="version_string" type="text" placeholder="请输入版本号, 如2.0.1 ,当前最新版本号 ({$versionString})" />
                        </div>
                        <div class="field-box">
                            <label>软件首页:</label>
                            <input class="span5 inline-input" name="server_url" type="text" placeholder="请输入首页地址." />
                        </div>
                        <div class="field-box">
                            <label>请选择更新类型:</label>
                            <div class="ui-select" style="width:100px;">
                                <select name="update_force">
                                    <option value="0" selected="" /> 非强制更新
                                    <option value="1" /> 强制更新
                                </select>
                            </div>
                        </div>
                        <div class="field-box">
                            <label>版本描述:</label>
                            <textarea class="span5" name="remark" rows="4" style=" height: 105px;"></textarea>
                        </div>

                        <div id="file-content">

                        </div>

                        <div class="span6 field-box actions">
                            <a href="javascript:void(0);" onclick="submitForm('version-form','__ACTION__')" class="btn-flat default" >提交新版本</a>
                            <a href="__APP__/Version" class="btn-flat gray" >返回</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- end main container -->

    <include file="./App/Admin/View/Include/js.html" />
    <include file="./App/Admin/View/Include/modal.html" />

    <script type="text/javascript" src="__PUBLIC__/Libs/plupload/plupload.full.min.js"></script>
    <script type="text/javascript">
        // Custom example logic

        var uploader = new plupload.Uploader({
            runtimes : 'html5,flash,silverlight,html4',
            browse_button : 'pickfiles', // you can pass in id...
            container: document.getElementById('container'), // ... or DOM Element itself
            url : '{:U("Version/upload")}',
            flash_swf_url : '__PUBLIC__/Libs/plupload/Moxie.swf',
            silverlight_xap_url : '__PUBLIC__/Libs/plupload/Moxie.xap',

            filters : {
                // Maximum file size
                max_file_size : '20mb',
                // Specify what files to browse for
                mime_types: [
                    {title : "Apk files", extensions : "apk,APK"}
                ]
            },

            init: {
                PostInit: function() {
                    document.getElementById('filelist').innerHTML = '';
                    document.getElementById('uploadfiles').onclick = function() {
                        uploader.start();
                        return false;
                    };
                },

                FilesAdded: function(up, files) {
                    plupload.each(files, function(file) {
                        document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
                    });
                },

                UploadProgress: function(up, file) {
                    document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
                },

                FileUploaded:function(up,file,result) {
                    var response =  $.parseJSON('' + result.response);
                    if (response.status == 1 || response.status == 2) {
                        document.getElementById("apk").value = response.path;
                    } else {
                        document.getElementById('console').innerHTML += "\nError #" + response.msg;
                    }
                },

                Error: function(up, err) {
                    document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
                }
            }
        });

        uploader.init();

    </script>

</body>
</html>